/*
 * @Description:
 * @Autor: liujinyin
 * @Date: 2021-07-02 17:28:46
 * @LastEditors: liujinyin
 * @LastEditTime: 2021-07-02 18:29:12
 */
package sqls

import "fmt"

const GetPermissionByOutID = `
select 
t.uid,
t.euid,
t.md5_secret,
t.sha1_secret,
t.sha256_secret,
t.sha512_secret,
t.hmac_secret,
t.aes_secret,
t.des_secret,
t.rsa_public_secret,
t.rsa_private_secret,
t.mer_cert, 
t.spl_cert,
t.root_cert,
t.cert_key, 
t.status,
date_format(t.expire_time,'%Y-%m-%d %H:%i:%s') expire_time,
t.create_time,
t.update_time 
from 
sas_secret_conf t where t.euid = @euid`

const UpdateSecret = `update 
sas_secret_conf t 
set t.%s = @secret, 
t.update_time = now(),
t.expire_time=if(isnull(@expire_time)||@expire_time = '',t.expire_time,@expire_time) 
where t.uid = @uid`

//UpdateSecretSQL 更新密钥sql
func UpdateSecretSQL(paramName string) string {
	return fmt.Sprintf(UpdateSecret, paramName)
}

const InsetNewData = `
insert into sas_secret_conf 
(euid,status,expire_time) 
values 
(@euid,@status,'2099-12-31 00:00:00')`

const AddSecret = `
update sas_secret_conf t 
set t.%s = @secret, 
t.status = t.status | @status, 
t.update_time = now() 
where t.uid = @uid`

//AddSecretSQL 添加新密钥sql
func AddSecretSQL(paramName string) string {
	return fmt.Sprintf(AddSecret, paramName)
}

const UpdateRSASecret = `
update sas_secret_conf t 
set 
t.rsa_public_secret = @rsa_public_secret, 
t.rsa_private_secret = @rsa_private_secret,
t.rsa_type = @rsa_type,
t.rsa_bits = @rsa_bits, 
t.status = t.status | @status, 
t.update_time = now(),
t.expire_time=if(isnull(@expire_time)||@expire_time = '',t.expire_time,@expire_time) 
where t.uid = @uid`

const UpdateCertSecret = `
update sas_secret_conf t 
set 
t.mer_cert = if(isnull(@mer_cert)||@mer_cert = '',t.mer_cert,@mer_cert), 
t.spl_cert = if(isnull(@spl_cert)||@spl_cert = '',t.spl_cert,@spl_cert),
t.root_cert =  if(isnull(@root_cert)||@root_cert = '',t.root_cert,@root_cert),
t.cert_key = if(isnull(@cert_key)||@cert_key = '',t.cert_key,@cert_key), 
t.status = t.status | @status, 
t.update_time = now(),
t.expire_time=if(isnull(@expire_time)||@expire_time = '',t.expire_time,@expire_time) 
where t.uid = @uid
`

const EnableSecret = `update sas_secret_conf t set t.status = t.status | @status, t.update_time = now() where t.uid = @uid`

const DisableSecret = `update sas_secret_conf t set t.status = t.status & ~@status, t.update_time = now() where t.uid = @uid`
